package com.heima.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import service.OssFileService;

@RequestMapping("/api/vm-service")
@RestController
@Slf4j
public class UploadController {

    @Autowired
    private OssFileService ossFileService;

    @PostMapping("/sku/fileUpload")
    public String upload(@RequestParam MultipartFile fileName) throws Exception {
        log.info("文件上传:{}",fileName.getOriginalFilename());
        String extName = fileName.getOriginalFilename().substring(fileName.getOriginalFilename().lastIndexOf("."));


        //String path = AliyunOSSUtils.upload(aliyunProperties.getEndpoint(), aliyunProperties.getBucketName(), file.getBytes(), extName);
        String path = ossFileService.upload(fileName.getBytes(),extName);
        return path;
    }
}
